
function popverLoad() {
    $('.product-popver').on('click', function ()
    {
        var src = $(this).attr('src-data');
        console.log(src);
        showimg(src);
    });

    $('.resouce-popver').on('click', function ()
    {
        var src = $(this).attr('src-data');
        showimg(src);
    });

    $('.slideshows-popver').on('click', function ()
    {
        var src = $(this).attr('src-data');
        showimg(src);
    });
    $('.sortClass').click(function () {
        var action = $(this).attr('attr-action');
        var sort = $(this).attr('attr-content');
        modifySort(action, sort);
    });

    function modifySort(action, sort) {
        $.ajax({
            url: "/modifySort",
            dataType: "json",
            data: {
                "action" : action,
                "sort" : sort
            },
            type: "POST",
            success: function(req) {
                if (req.status == 'success')
                {
                    $.pjax.reload('#pjax-container');
                } else {
                    swal(req.msg, '', 'error');
                }
            }
        });
    }

    /**
     * @see https://www.twblogs.net/a/5ca40f27bd9eee59d332abf8
     * @param src
     */
    function showimg(src) {
        if (src.length == null || src == "") {
            layer.msg("缺少图片链接！");
            return;
        }

        var loading = layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });

        var img = new Image();
        img.onload = function () {//避免圖片還未加載完成無法獲取到圖片的大小。
            //避免圖片太大，導致彈出展示超出了網頁顯示訪問，所以圖片大於瀏覽器時下窗口可視區域時，進行等比例縮小。
            var max_height = $(window).height() - 100;
            var max_width = $(window).width();

            //rate1，rate2，rate3 三個比例中取最小的。
            var rate1 = max_height / img.height;
            var rate2 = max_width / img.width;
            var rate3 = 1;
            var rate = Math.min(rate1, rate2, rate3);
            //等比例縮放
            var imgHeight = img.height * rate; //獲取圖片高度
            var imgWidth = img.width * rate; //獲取圖片寬度

            var imgHtml = "<img src='" + src + "' width='" + imgWidth + "px' height='" + imgHeight + "px'/>";
            layer.close(loading);
            //彈出層
            layer.open({
                type: 1,
                title: false,//不顯示標題
                closeBtn: 0,
                area: ['auto', 'auto'],
                skin: 'layui-layer-nobg', //沒有背景色
                shadeClose: true,
                content: imgHtml
            });
        }
        img.src = src;
    }
}

function auditingLoad(token) {
    $('.auditing').on('click', function ()
    {
        var operating = $(this).attr('data-auditing-operating');
        var product_id = $(this).attr('data-auditing-id');
        var process = $(this).attr('data-auditing-process');
        auditing(operating, process, product_id);
    });

    function auditing(operating, process, product_id) {

        $.ajax({
            url: "/admin/product/auditing",
            dataType: "json",
            data: {
                "_token" : token,
                "operating" : operating,
                "product_id" : product_id,
                "process" : process
            },
            type: "POST",
            success: function(req) {
                if (req.status == 'success')
                {
                    $.pjax.reload('#pjax-container');
                } else {
                    swal(req.msg, '', 'error');
                }
            }
        });
    }
}

